package com.iplant.wms.serviceImpl.dao.batch;

import com.iplant.base.po.OutResult;
import com.iplant.base.po.Pagination;
import com.iplant.base.po.enums.ExceptionTypes;
import com.iplant.base.utils.annotation.dao.DBBaseDAO;
import com.iplant.base.utils.sql.BaseDAO;
import com.iplant.basic.service.po.bms.BMSEmployee;
import com.iplant.wms.service.po.batch.MSSBatchRule;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.*;


@DBBaseDAO(MSSBatchRule.class)
public class MSSBatchRuleDAO extends BaseDAO {

    private static MSSBatchRuleDAO Instance = null;
    private static Logger logger = LoggerFactory.getLogger(MSSBatchRuleDAO.class);

    private MSSBatchRuleDAO() {
        super("");this.Init();
    }

    public static MSSBatchRuleDAO getInstance() {
        if (Instance == null) {
            Instance = new MSSBatchRuleDAO();
        }
        return Instance;
    }



    public void MSS_DeleteBatchRule(BMSEmployee wLoginUser, MSSBatchRule wBatchRule, OutResult<Integer> wErrorCode) {
        wErrorCode.set(0);

        try {
            if (wBatchRule == null || wBatchRule.ID <= 0) {
                wErrorCode.set(ExceptionTypes.Parameter.getValue());
                return;
            }
            int wRows = this.DeletePO(wLoginUser, wBatchRule, wErrorCode);

            if (wRows > 0) {
                MSSBatchPropDAO.getInstance().MSS_DeleteBatchProp(wLoginUser, wBatchRule.ID, wErrorCode);
                MSSBatchRangeDAO.getInstance().MSS_DeleteBatchRange(wLoginUser, wBatchRule.ID, wErrorCode);
            }

        } catch (Exception ex) {
            wErrorCode.set(ExceptionTypes.DBSQL.getValue());
            logger.error("MSS_DeleteBatchRule", ex);
        }
    }




    public List<MSSBatchRule> MSS_QueryBatchRuleList(
            BMSEmployee wLoginUser, String wName,
            int wActive,
            Pagination wPagination, OutResult<Integer> wErrorCode) {

        Map<String, Object> wParams = new HashMap<String, Object>();
        wParams.put("Name", wName);
        wParams.put("Active", wActive);

        return  this.SelectPOList(wLoginUser,  wParams,  wPagination, wErrorCode);
    }

}
